import dbus

class Trophy (object):

    def __init__(self):

        self.ID = ""
        self.Title = ""
        self.Description = {}
        self.IconPath = ""
        self.SetName = ""
        self.Application = ""
        self.ApplicationFriendlyName = ""
        self.Priority = 0
        self.SetIcon = ""
        self.Unlocked = False
        self.Timestamp= 0
        self.StockIcon = ""

    def __str__(self):
        return str((self.ID,
            self.Title,
            self.Description,
            self.IconPath,
            self.SetName,
            self.Application,
            self.ApplicationFriendlyName,
            self.Priority,
            self.SetIcon,
            self.Unlocked,
            self.Timestamp,
            self.StockIcon))

    def getDescription(self, locale_str):
        if locale_str in self.Description:
            return self.Description[locale_str]
        else:
            return self.Description['en-us']


def new_trophy_from_dbus(data):

    t = Trophy()

    t.ID = str(data[0])
    t.Title = str(data[1])
    description = data[2]

    for it in description:
        t.Description[str(it[0])] = str(it[1])

    t.IconPath = str(data[3])
    t.SetName = str(data[4])
    t.Application = str(data[5])
    t.ApplicationFriendlyName = str(data[6])
    t.Priority = int(data[7])
    t.SetIcon = str(data[8])
    t.Unlocked = bool(data[9])
    t.Timestamp= int(data[10])
    t.StockIcon = str(data[11])

    return t
